package com.guaju.yueshangLife.net;

import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;
import com.guaju.yueshangLife.base.GoodsDetail;
import com.guaju.yueshangLife.bean.AboutUsBean;
import com.guaju.yueshangLife.bean.AddAddressBean;
import com.guaju.yueshangLife.bean.AddCartResultBean;
import com.guaju.yueshangLife.bean.AddComment;
import com.guaju.yueshangLife.bean.AdviceBean;
import com.guaju.yueshangLife.bean.AlipayBean;
import com.guaju.yueshangLife.bean.CancleOrderBean;
import com.guaju.yueshangLife.bean.CartBean;
import com.guaju.yueshangLife.bean.CartStringBean;
import com.guaju.yueshangLife.bean.CategoryTotal;
import com.guaju.yueshangLife.bean.CodeLoginEvent;
import com.guaju.yueshangLife.bean.CommentsBean;
import com.guaju.yueshangLife.bean.CreateOrderBean;
import com.guaju.yueshangLife.bean.DelResultBean;
import com.guaju.yueshangLife.bean.GoodsDetailStringBean;
import com.guaju.yueshangLife.bean.GoodsListTotal;
import com.guaju.yueshangLife.bean.HomeTotal;
import com.guaju.yueshangLife.bean.LoginBean;
import com.guaju.yueshangLife.bean.LoginInfoBean;
import com.guaju.yueshangLife.bean.MeBean;
import com.guaju.yueshangLife.bean.MeDetailBean;
import com.guaju.yueshangLife.bean.MeOrder;
import com.guaju.yueshangLife.bean.MePermissionBean;
import com.guaju.yueshangLife.bean.MePocketBean;
import com.guaju.yueshangLife.bean.MineOrder;
import com.guaju.yueshangLife.bean.MyAddressBean;
import com.guaju.yueshangLife.bean.Offline;
import com.guaju.yueshangLife.bean.OrderDeleteBean;
import com.guaju.yueshangLife.bean.OrderDetailBean;
import com.guaju.yueshangLife.bean.PicBean;
import com.guaju.yueshangLife.bean.PocketLogsBean;
import com.guaju.yueshangLife.bean.PrepareOrderBean;
import com.guaju.yueshangLife.bean.ReceiveGoods;
import com.guaju.yueshangLife.bean.SetDefaultBean;
import com.guaju.yueshangLife.bean.UpdateMineInfo;
import com.guaju.yueshangLife.event.CodeEvent;
import com.guaju.yueshangLife.utils.PreferenceUtil;
import com.guaju.yueshangLife.utils.ToastUtil;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.http.Field;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class ApiEntity {
    private static final String TAG = "ApiEntity";
    private static Gson gson;

    static {


        gson = new Gson();
    }

    private static Call<GoodsListTotal> goods;


    public static void getLoginCode(final String mobile) {
        Observable<String> observable = ApiClient.getInstance().getApiService().loginSmsCode(mobile);
        observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(

//                        new Action1<String>() {
//                    @Override
//                    public void call(String s) {
//                        try {
//                            JSONObject jsonObject = new JSONObject(s);
//                            if (200 == jsonObject.getInt("code")) {
//                                //说明存在账号，并已经发送验证码
//                                JSONObject data = jsonObject.getJSONObject("data");
//                                String verify_key = data.getString("verify_key");
//                                CodeEvent codeLoginEvent = new CodeEvent(mobile, verify_key);
//                                EventBus.getDefault().post(codeLoginEvent);
//                            } else {
//                                if (jsonObject.has("msg")) {
//                                    String msg = jsonObject.getString("msg");
//                                    if (TextUtils.equals(msg, "api.system.request.frequent")) {
//                                        ToastUtil.show("操作过于频繁,稍后再试~");
//                                    } else if (TextUtils.equals(msg, "账户不存在")) {
//                                        ToastUtil.show("账户未注册,请您注册或者检查您的账户~");
//                                    }
//                                } else {
//                                    ToastUtil.show("内部错误~");
//                                }
//
//                            }
//
//
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//
//
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("getLoginCode网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                try {
                                    JSONObject jsonObject = new JSONObject(s);
                                    if (200 == jsonObject.getInt("code")) {
                                        //说明存在账号，并已经发送验证码
                                        JSONObject data = jsonObject.getJSONObject("data");
                                        String verify_key = data.getString("verify_key");
                                        CodeEvent codeLoginEvent = new CodeEvent(mobile, verify_key);
                                        EventBus.getDefault().post(codeLoginEvent);
                                    } else {
                                        if (jsonObject.has("msg")) {
                                            String msg = jsonObject.getString("msg");
                                            if (TextUtils.equals(msg, "api.system.request.frequent")) {
                                                ToastUtil.show("操作过于频繁,稍后再试~");
                                            } else if (TextUtils.equals(msg, "账户不存在")) {
                                                ToastUtil.show("账户未注册,请您注册或者检查您的账户~");
                                            }
                                        } else {
                                            ToastUtil.show("内部错误~");
                                        }

                                    }


                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                );

    }

    public static void codeLogin(String verify_key, String verify_code) {
        ApiClient.getInstance().getApiService().verifyCode(verify_key, verify_code).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io())
                .subscribe(

//                        new Action1<String>() {
//                    @Override
//                    public void call(String s) {
//                        try {
//                            JSONObject jsonObject = new JSONObject(s);
//                            if (200 == jsonObject.getInt("code")) {
//                                //说明存在账号，并已经发送验证码
//                                String msg = jsonObject.getString("msg");
//                                JSONObject data = jsonObject.getJSONObject("data");
//                                String token_type = data.getString("token_type");
//                                String access_token = data.getString("access_token");
//                                CodeLoginEvent codeLoginEvent = new CodeLoginEvent(200, token_type, msg, access_token);
//                                EventBus.getDefault().post(codeLoginEvent);
////
//                            } else if (500 == jsonObject.getInt("code")) {
//                                String msg = jsonObject.getString("msg");
//                                CodeLoginEvent codeLoginEvent = new CodeLoginEvent(500, null, msg, null);
//                                EventBus.getDefault().post(codeLoginEvent);
//                            } else if (412 == jsonObject.getInt("code")) {
//                                String msg = jsonObject.getString("msg");
//                                JSONObject data = jsonObject.getJSONObject("data");
//                                String token_type = data.getString("token_type");
//                                String access_token = data.getString("access_token");
//                                CodeLoginEvent codeLoginEvent = new CodeLoginEvent(412, token_type, msg, access_token);
//                                EventBus.getDefault().post(codeLoginEvent);
//                            } else {
//                                int code = jsonObject.getInt("code");
//                                String msg = jsonObject.getString("msg");
//                                JSONObject data = jsonObject.getJSONObject("data");
//                                String token_type = data.getString("token_type");
//                                String access_token = data.getString("access_token");
//                                CodeLoginEvent codeLoginEvent = new CodeLoginEvent(code, token_type, msg, access_token);
//                                EventBus.getDefault().post(codeLoginEvent);
//                            }
//
//
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("codeLogin网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                try {
                                    JSONObject jsonObject = new JSONObject(s);
                                    if (200 == jsonObject.getInt("code")) {
                                        //说明存在账号，并已经发送验证码
                                        String msg = jsonObject.getString("msg");
                                        JSONObject data = jsonObject.getJSONObject("data");
                                        String token_type = data.getString("token_type");
                                        String access_token = data.getString("access_token");
                                        CodeLoginEvent codeLoginEvent = new CodeLoginEvent(200, token_type, msg, access_token);
                                        EventBus.getDefault().post(codeLoginEvent);
//
                                    } else if (500 == jsonObject.getInt("code")) {
                                        String msg = jsonObject.getString("msg");
                                        CodeLoginEvent codeLoginEvent = new CodeLoginEvent(500, null, msg, null);
                                        EventBus.getDefault().post(codeLoginEvent);
                                    } else if (412 == jsonObject.getInt("code")) {
                                        String msg = jsonObject.getString("msg");
                                        JSONObject data = jsonObject.getJSONObject("data");
                                        String token_type = data.getString("token_type");
                                        String access_token = data.getString("access_token");
                                        CodeLoginEvent codeLoginEvent = new CodeLoginEvent(412, token_type, msg, access_token);
                                        EventBus.getDefault().post(codeLoginEvent);
                                    } else {
                                        int code = jsonObject.getInt("code");
                                        String msg = jsonObject.getString("msg");
                                        JSONObject data = jsonObject.getJSONObject("data");
                                        String token_type = data.getString("token_type");
                                        String access_token = data.getString("access_token");
                                        CodeLoginEvent codeLoginEvent = new CodeLoginEvent(code, token_type, msg, access_token);
                                        EventBus.getDefault().post(codeLoginEvent);
                                    }


                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                );
    }

    public static void getRegistCode(final String mobile) {
        ApiClient.getInstance().getApiService().registSmsCode(mobile).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io())
                .subscribe(

//                        new Action1<String>() {
//                    @Override
//                    public void call(String s) {
//                        try {
//                            JSONObject jsonObject = new JSONObject(s);
//                            if (200 == jsonObject.getInt("code")) {
//                                //说明存在账号，并已经发送验证码
//                                JSONObject data = jsonObject.getJSONObject("data");
//                                String verify_key = data.getString("verify_key");
//                                CodeEvent codeLoginEvent = new CodeEvent(mobile, verify_key);
//                                EventBus.getDefault().post(codeLoginEvent);
//                            } else {
//                                if (jsonObject.has("msg")) {
//                                    String msg = jsonObject.getString("msg");
//                                    if (TextUtils.equals(msg, "api.system.request.frequent")) {
//                                        ToastUtil.show("操作过于频繁,稍后再试~");
//                                    } else if (TextUtils.equals(msg, "账户不存在")) {
//                                        ToastUtil.show("账户未注册,请您注册或者检查您的账户~");
//                                    }
//                                } else {
//                                    ToastUtil.show("内部错误");
//                                }
//                            }
//
//
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                try {
                                    JSONObject jsonObject = new JSONObject(s);
                                    if (200 == jsonObject.getInt("code")) {
                                        //说明存在账号，并已经发送验证码
                                        JSONObject data = jsonObject.getJSONObject("data");
                                        String verify_key = data.getString("verify_key");
                                        CodeEvent codeLoginEvent = new CodeEvent(mobile, verify_key);
                                        EventBus.getDefault().post(codeLoginEvent);
                                    } else {
                                        if (jsonObject.has("msg")) {
                                            String msg = jsonObject.getString("msg");
                                            if (TextUtils.equals(msg, "api.system.request.frequent")) {
                                                ToastUtil.show("操作过于频繁,稍后再试~");
                                            } else if (TextUtils.equals(msg, "账户不存在")) {
                                                ToastUtil.show("账户未注册,请您注册或者检查您的账户~");
                                            }
                                        } else {
                                            ToastUtil.show("内部错误");
                                        }
                                    }


                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                );
    }

    public static void verifyCode(String verify_key, String verify_code) {
        ApiClient.getInstance().getApiService().verifyCode(verify_key, verify_code).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io())
                .subscribe(

//                        new Action1<String>() {
//                    @Override
//                    public void call(String s) {
//                        try {
//                            JSONObject jsonObject = new JSONObject(s);
//                            if (412 == jsonObject.getInt("code")) {
//                                LoginBean loginBean = gson.fromJson(s, LoginBean.class);
//                                EventBus.getDefault().post(loginBean);
//                            } else if (500 == jsonObject.getInt("code")) {
//                                String msg = jsonObject.getString("msg");
//                                EventBus.getDefault().post(msg);
//                            } else {
//                                String msg = jsonObject.getString("msg");
//                                ToastUtil.show(msg);
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                try {
                                    JSONObject jsonObject = new JSONObject(s);
                                    if (412 == jsonObject.getInt("code")) {
                                        LoginBean loginBean = gson.fromJson(s, LoginBean.class);
                                        EventBus.getDefault().post(loginBean);
                                    } else if (500 == jsonObject.getInt("code")) {
                                        String msg = jsonObject.getString("msg");
                                        EventBus.getDefault().post(msg);
                                    } else {
                                        String msg = jsonObject.getString("msg");
                                        ToastUtil.show(msg);
                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                );
    }

    public static void category() {
        final Observable<CategoryTotal> category = ApiClient.getInstance().getApiService().category();
        category.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(

//                        new Action1<CategoryTotal>() {
//                    @Override
//                    public void call(CategoryTotal categoryTotal) {
//                        EventBus.getDefault().post(categoryTotal);
//                    }
//                }
                        new Subscriber<CategoryTotal>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(CategoryTotal categoryTotal) {
                                EventBus.getDefault().post(categoryTotal);
                            }
                        }
                );

    }

    public static void home() {
        final Observable<HomeTotal> category = ApiClient.getInstance().getApiService().home();
        category.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<HomeTotal>() {
//                    @Override
//                    public void call(HomeTotal homeTotal) {
//                        EventBus.getDefault().post(homeTotal);
//                    }
//                }
                        new Subscriber<HomeTotal>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(HomeTotal homeTotal) {
                                EventBus.getDefault().post(homeTotal);
                            }
                        }
                );

    }

    public static void me() {
        final Observable<MeBean> category = ApiClient.getInstance().getApiService().me();
        category.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<MeBean>() {
//                    @Override
//                    public void call(MeBean bean) {
//                        EventBus.getDefault().post(bean);
//
//                    }
//                }
                        new Subscriber<MeBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(MeBean meBean) {
                                EventBus.getDefault().post(meBean);
                            }
                        }
                );

    }

    public static void mePermission() {
        final Observable<MePermissionBean> category = ApiClient.getInstance().getApiService().mePermission();
        category.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<MePermissionBean>() {
//                    @Override
//                    public void call(MePermissionBean bean) {
//                        EventBus.getDefault().post(bean);
//
//                    }
//                }
                        new Subscriber<MePermissionBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(MePermissionBean mePermissionBean) {
                                EventBus.getDefault().post(mePermissionBean);
                            }
                        }
                );

    }

    public static void mePocket() {
        final Observable<MePocketBean> mepocket = ApiClient.getInstance().getApiService().mePocket();
        mepocket.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<MePocketBean>() {
//                    @Override
//                    public void call(MePocketBean bean) {
//                        EventBus.getDefault().post(bean);
//
//                    }
//                }
                        new Subscriber<MePocketBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(MePocketBean mePocketBean) {
                                EventBus.getDefault().post(mePocketBean);
                            }
                        }
                );

    }

    public static void mePocketLogs(int page, int limit, Callback<PocketLogsBean> callback) {
        Call<PocketLogsBean> pocketLogsBeanCall =
                ApiClient.getInstance().getApiService().pocketLogs(page, limit);
        pocketLogsBeanCall.enqueue(callback);

    }


    public static void order(String ids) {
        final Observable<String> category = ApiClient.getInstance().getApiService().order(ids);
        category.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(

//                        new Action1<String>() {
//                    @Override
//                    public void call(String str) {
//                        EventBus.getDefault().post(str);
//                        try {
//                            JSONObject jsonObject = new JSONObject(str);
//                            int code = jsonObject.getInt("code");
//                            if (200 == code) {
//                                JSONObject data = jsonObject.getJSONObject("data");
//
//
//                            } else {
//
//
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                EventBus.getDefault().post(s);
                                try {
                                    JSONObject jsonObject = new JSONObject(s);
                                    int code = jsonObject.getInt("code");
                                    if (200 == code) {
                                        JSONObject data = jsonObject.getJSONObject("data");


                                    } else {


                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                );

    }


    public static void goods(int page, int limit, String
            cate, Callback<GoodsListTotal> callback) {
        final Call<GoodsListTotal> goods = ApiClient.getInstance().getApiService().goods(page, limit, cate);
        goods.enqueue(callback);


    }


    public static void goods(int page, String cate, Callback<GoodsListTotal> callback) {
        if (TextUtils.isEmpty(cate)) {
            Call<GoodsListTotal> goods = ApiClient.getInstance().getApiService().goods(page);
            goods.enqueue(callback);
        } else {
            Call<GoodsListTotal> goods = ApiClient.getInstance().getApiService().goods(page, cate);
            goods.enqueue(callback);

        }
    }

    public static void goods(int page, String cate, String sort, String isIncrease, Callback<GoodsListTotal> callback) {
        if (TextUtils.isEmpty(cate)) {

            if (TextUtils.equals("sales", sort)) {
                goods = ApiClient.getInstance().getApiService().goodsSortBySales(page, isIncrease);
            } else if (TextUtils.equals("price", sort)) {
                goods = ApiClient.getInstance().getApiService().goodsSortByPrice(page, isIncrease);
            } else if (TextUtils.equals("publish", sort)) {
                goods = ApiClient.getInstance().getApiService().goodsSortByPublish(page, isIncrease);
            }
            goods.enqueue(callback);
        } else {
            if (TextUtils.equals("sales", sort)) {
                goods = ApiClient.getInstance().getApiService().goodsSortBySales(page, cate, isIncrease);
            } else if (TextUtils.equals("price", sort)) {
                goods = ApiClient.getInstance().getApiService().goodsSortByPrice(page, cate, isIncrease);
            } else if (TextUtils.equals("publish", sort)) {
                goods = ApiClient.getInstance().getApiService().goodsSortByPublish(page, cate, isIncrease);
            }
            goods.enqueue(callback);

        }
    }

    public static void goodsDetail(String goods_id) {
        final GoodsDetail goodsDetail = null;
        final Observable<GoodsDetail> category = ApiClient.getInstance().getApiService().goodsDetail(goods_id);
        category.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<GoodsDetail>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        EventBus.getDefault().post(goodsDetail);
                    }

                    @Override
                    public void onNext(GoodsDetail goodsDetail) {
                        EventBus.getDefault().post(goodsDetail);
                    }
                });
//

    }

    public static void alipay(int orderId, String password) {
        final Observable<AlipayBean> category = ApiClient.getInstance().getApiService().pay(orderId, password, 2);
        category.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<AlipayBean>() {
                            @Override
                            public void onCompleted() {
                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(AlipayBean bean) {
                                EventBus.getDefault().post(bean);
                            }
                        });
    }

    public static void goodsDetailBean(String goods_id) {
        final Observable<String> category = ApiClient.getInstance().getApiService().goodsDetailString(goods_id);
        category.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<String>() {
//                    @Override
//                    public void call(String str) {
//                        try {
//                            JSONObject jsonObject = new JSONObject(str);
//                            int code = jsonObject.getInt("code");
//                            if (200 == code) {
//                                GoodsDetail goodsDetail = gson.fromJson(str, GoodsDetail.class);
//                                EventBus.getDefault().post(goodsDetail);
//                            } else {
//                                GoodsDetailStringBean goodsDetailStringBean = new GoodsDetailStringBean(str);
//                                EventBus.getDefault().post(goodsDetailStringBean);
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                try {
                                    JSONObject jsonObject = new JSONObject(s);
                                    int code = jsonObject.getInt("code");
                                    if (200 == code) {
                                        GoodsDetail goodsDetail = gson.fromJson(s, GoodsDetail.class);
                                        EventBus.getDefault().post(goodsDetail);
                                    } else {
                                        GoodsDetailStringBean goodsDetailStringBean = new GoodsDetailStringBean(s);
                                        EventBus.getDefault().post(goodsDetailStringBean);
                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                );

    }

    public static void goodsDetailString(String goods_id) {
        final Observable<String> category = ApiClient.getInstance().getApiService().goodsDetailString(goods_id);
        category.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<String>() {
//                    @Override
//                    public void call(String str) {
//                        EventBus.getDefault().post(str);
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                EventBus.getDefault().post(s);
                            }
                        }

                );

    }

    public static void setPassword(String password) {
        String s = PreferenceUtil.getTokenType() + PreferenceUtil.getToken();
        final Observable<String> category = ApiClient.getInstance().getApiService().setPassword(password, password);
        category.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("GUAJU", "onError:" + e.getMessage());
                    }

                    @Override
                    public void onNext(String str) {
                        EventBus.getDefault().post(str);
                    }

                });

    }

    public static void addToCart(int id, int sku_id, String num) {
        Observable<String> addToCart = ApiClient.getInstance().getApiService().addCart(id, sku_id, num);
        addToCart.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(

//                        new Action1<String>() {
//                    @Override
//                    public void call(String s) {
//                        try {
//                            JSONObject jsonObject = new JSONObject(s);
//                            int code = jsonObject.getInt("code");
//                            String msg = jsonObject.getString("msg");
//                            AddCartResultBean addCartResultBean = new AddCartResultBean(code, msg);
//                            EventBus.getDefault().post(addCartResultBean);
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//
//                    }
//                }
                        new Subscriber<String>() {

                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                try {
                                    JSONObject jsonObject = new JSONObject(s);
                                    int code = jsonObject.getInt("code");
                                    String msg = jsonObject.getString("msg");
                                    AddCartResultBean addCartResultBean = new AddCartResultBean(code, msg);
                                    EventBus.getDefault().post(addCartResultBean);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                );
    }

    public static void cart() {
        Observable<CartBean> cart = ApiClient.getInstance().getApiService().cart();
        cart.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(

//                        new Action1<CartBean>() {
//                    @Override
//                    public void call(CartBean cartBean) {
//                        EventBus.getDefault().post(cartBean);
//
//                    }
//                }
                        new Subscriber<CartBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(CartBean cartBean) {
                                EventBus.getDefault().post(cartBean);
                            }
                        }

                );
    }

    public static void cartString() {
        Observable<String> cart = ApiClient.getInstance().getApiService().cartString();
        cart.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<String>() {
////                    @Override
////                    public void call(String str) {
////                        CartStringBean cartStringBean = new CartStringBean(str);
////                        EventBus.getDefault().post(cartStringBean);
////
////                    }
////                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                CartStringBean cartStringBean = new CartStringBean(s);
                                EventBus.getDefault().post(cartStringBean);
                            }
                        }
                );
    }

    public static void login(String mobile, String password) {
        ApiClient.getInstance().getApiService().login(mobile, password).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io())
                .subscribe(

//                        new Action1<String>() {
//                    @Override
//                    public void call(String s) {
//                        try {
//                            JSONObject jsonObject = new JSONObject(s);
//                            if (200 == jsonObject.getInt("code")) {
//                                //说明存在账号，并已经发送验证码
//                                String msg = jsonObject.getString("msg");
//                                JSONObject data = jsonObject.getJSONObject("data");
//                                String token_type = data.getString("token_type");
//                                String access_token = data.getString("access_token");
//                                CodeLoginEvent codeLoginEvent = new CodeLoginEvent(200, token_type, msg, access_token);
//                                EventBus.getDefault().post(codeLoginEvent);
////
//                            } else if (500 == jsonObject.getInt("code")) {
//                                String msg = jsonObject.getString("msg");
//                                CodeLoginEvent codeLoginEvent = new CodeLoginEvent(500, null, msg, null);
//                                EventBus.getDefault().post(codeLoginEvent);
//                            } else {
//                                String msg = jsonObject.getString("msg");
//                                CodeLoginEvent codeLoginEvent = new CodeLoginEvent(jsonObject.getInt("code"), null, msg, null);
//                                EventBus.getDefault().post(codeLoginEvent);
//                            }
//
//
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                try {
                                    JSONObject jsonObject = new JSONObject(s);
                                    if (200 == jsonObject.getInt("code")) {
                                        //说明存在账号，并已经发送验证码
                                        String msg = jsonObject.getString("msg");
                                        JSONObject data = jsonObject.getJSONObject("data");
                                        String token_type = data.getString("token_type");
                                        String access_token = data.getString("access_token");
                                        CodeLoginEvent codeLoginEvent = new CodeLoginEvent(200, token_type, msg, access_token);
                                        EventBus.getDefault().post(codeLoginEvent);
//
                                    } else if (500 == jsonObject.getInt("code")) {
                                        String msg = jsonObject.getString("msg");
                                        CodeLoginEvent codeLoginEvent = new CodeLoginEvent(500, null, msg, null);
                                        EventBus.getDefault().post(codeLoginEvent);
                                    } else {
                                        String msg = jsonObject.getString("msg");
                                        CodeLoginEvent codeLoginEvent = new CodeLoginEvent(jsonObject.getInt("code"), null, msg, null);
                                        EventBus.getDefault().post(codeLoginEvent);
                                    }


                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                );
    }


    public static void aboutUs() {
        Observable<AboutUsBean> about = ApiClient.getInstance().getApiService().about();
        about.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<AboutUsBean>() {
//                    @Override
//                    public void call(AboutUsBean bean) {
//                        EventBus.getDefault().post(bean);
//                    }
//                }
                        new Subscriber<AboutUsBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(AboutUsBean bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void advice(String content, int type, String mobile, String email, String
            other) {
        Observable<AdviceBean> about = ApiClient.getInstance().getApiService().advice(content, type, mobile, email, other);
        about.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(

//                        new Action1<AdviceBean>() {
//                    @Override
//                    public void call(AdviceBean bean) {
//                        EventBus.getDefault().post(bean);
//                    }
//                }
                        new Subscriber<AdviceBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(AdviceBean adviceBean) {
                                EventBus.getDefault().post(adviceBean);
                            }
                        }
                );
    }

    public static void delFromCart(String ids) {
        Observable<DelResultBean> about = ApiClient.getInstance().getApiService().delFromCart(ids);
        about.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<DelResultBean>() {
//                    @Override
//                    public void call(DelResultBean bean) {
//                        EventBus.getDefault().post(bean);
//                    }
//                }
                        new Subscriber<DelResultBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(DelResultBean delResultBean) {
                                EventBus.getDefault().post(delResultBean);
                            }
                        }
                );
    }

    public static void updateCartGoods(int id, int num) {
        Observable<String> about = ApiClient.getInstance().getApiService().updateCartGoods(id, num);
        about.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(

//                        new Action1<String>() {
//                    @Override
//                    public void call(String bean) {
//                        EventBus.getDefault().post(bean);
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                EventBus.getDefault().post(s);
                            }
                        }
                );
    }

    public static void logout() {
        Observable<String> logout = ApiClient.getInstance().getApiService().logOut();
        logout.subscribeOn(Schedulers.io())

                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<String>() {
//                    @Override
//                    public void call(String s) {
//                        EventBus.getDefault().post(s);
//                        PreferenceUtil.setIsLogin(false);
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                EventBus.getDefault().post(s);
                                PreferenceUtil.setIsLogin(false);
                            }
                        }

                );
    }

    public static void address(int code) {
        Observable<String> address = ApiClient.getInstance().getApiService().address(code);
        address.subscribeOn(Schedulers.io())

                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(

//                        new Action1<String>() {
//                    @Override
//                    public void call(String s) {
//                        EventBus.getDefault().post(s);
//
//                    }
//                }

                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                EventBus.getDefault().post(s);
                            }
                        }

                );
    }

    public static void address() {
        Observable<String> address = ApiClient.getInstance().getApiService().address();
        address.subscribeOn(Schedulers.io())

                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<String>() {
//                    @Override
//                    public void call(String s) {
//                        EventBus.getDefault().post(s);
//
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                EventBus.getDefault().post(s);
                            }
                        }
                );
    }

    public static void meAddress() {
        Observable<MyAddressBean> meaddress = ApiClient.getInstance().getApiService().meAddress();
        meaddress.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<MyAddressBean>() {
//                    @Override
//                    public void call(MyAddressBean myAddressBean) {
//                        EventBus.getDefault().post(myAddressBean);
//
//                    }
//                }
                        new Subscriber<MyAddressBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(MyAddressBean myAddressBean) {
                                EventBus.getDefault().post(myAddressBean);
                            }
                        }
                );
    }


    public static void setDefaultAddress(int address) {
        Observable<SetDefaultBean> result = ApiClient.getInstance().getApiService().setDefaultAddress(address);
        result.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<SetDefaultBean>() {
//                    @Override
//                    public void call(SetDefaultBean bean) {
//                        EventBus.getDefault().post(bean);
//
//                    }
//                }
                        new Subscriber<SetDefaultBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(SetDefaultBean setDefaultBean) {
                                EventBus.getDefault().post(setDefaultBean);
                            }
                        }
                );
    }

    public static void couponGoods() {
        Observable<String> coupon = ApiClient.getInstance().getApiService().coupon();
        coupon.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<String>() {
//                    @Override
//                    public void call(String s) {
//                        EventBus.getDefault().post(s);
//
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                EventBus.getDefault().post(s);
                            }
                        }
                );
    }

    public static void addAddress(int province, int city, int district, String address, String
            contact_name, String contact_phone, int is_default) {
        Observable<AddAddressBean> meaddress = ApiClient.getInstance().getApiService().addAddress(province, city, district, address, contact_name, contact_phone, is_default);
        meaddress.subscribeOn(Schedulers.io())

                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<AddAddressBean>() {
//                    @Override
//                    public void call(AddAddressBean bean) {
//                        EventBus.getDefault().post(bean);
//
//                    }
//                }
                        new Subscriber<AddAddressBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(AddAddressBean addAddressBean) {
                                EventBus.getDefault().post(addAddressBean);
                            }
                        }
                );

    }

    public static void prepareOrder(String ids) {
        final Observable<String> coupon = ApiClient.getInstance().getApiService().prepareOrder(ids);
        coupon.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<String>() {
//                    @Override
//                    public void call(String str) {
//                        Log.e("guajujerry", "call: " + str);
//                        int code;
//                        PrepareOrderBean prepareOrderBean = null;
//                        try {
//                            JSONObject jsonObject = new JSONObject(str);
//                            if (jsonObject.has("code")) {
//                                code = jsonObject.getInt("code");
//                                if (200 == code) {
//                                    prepareOrderBean = ApiEntity.gson.fromJson(str, PrepareOrderBean.class);
//                                    EventBus.getDefault().post(prepareOrderBean);
//                                } else {
//                                    if (jsonObject.has("msg")) {
//                                        String msg = jsonObject.getString("msg");
//                                        ToastUtil.show(msg);
//                                    } else {
//
//                                        ToastUtil.show("数据异常");
//                                    }
//                                }
//
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//
//
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String str) {
                                int code;
                                PrepareOrderBean prepareOrderBean = null;
                                try {
                                    JSONObject jsonObject = new JSONObject(str);
                                    if (jsonObject.has("code")) {
                                        code = jsonObject.getInt("code");
                                        if (200 == code) {
                                            prepareOrderBean = ApiEntity.gson.fromJson(str, PrepareOrderBean.class);
                                            EventBus.getDefault().post(prepareOrderBean);
                                        } else {
                                            if (jsonObject.has("msg")) {
                                                String msg = jsonObject.getString("msg");
                                                ToastUtil.show(msg);
                                            } else {

                                                ToastUtil.show("数据异常");
                                            }
                                        }

                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                );
    }

    public static void creatOrder(String ids, String remark, int address, int payment, String
            postage) {
        Observable<CreateOrderBean> coupon = ApiClient.getInstance().getApiService().createOrder(ids, remark, address, payment, postage);
        coupon.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<CreateOrderBean>() {
//                    @Override
//                    public void call(CreateOrderBean bean) {
//                        EventBus.getDefault().post(bean);
//
//                    }
//                }
                        new Subscriber<CreateOrderBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(CreateOrderBean bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }


    public static void meOrder(String status, int page, int limit) {
        Observable<MineOrder> meOrder = ApiClient.getInstance().getApiService().meOrder(status, page, limit);
        meOrder.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<MineOrder>() {
//                    @Override
//                    public void call(MeOrder bean) {
//                        EventBus.getDefault().post(bean);
//                    }
//                }
                        new Subscriber<MineOrder>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {

                                Log.e(TAG, "onError: " + e.getMessage());
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(MineOrder meOrder) {
                                EventBus.getDefault().post(meOrder);
                            }
                        }
                );
    }


    public static void meOrderCall(String status, int page, int limit, Callback callback) {
        Call<MineOrder> meOrder = ApiClient.getInstance().getApiService().meOrderCall(status, page, limit);
        meOrder.enqueue(callback);
    }

    public static void comments(String product_id, int filter, int page, int limit, Callback<
            CommentsBean> callback) {
        Call<CommentsBean> comments = ApiClient.getInstance().getApiService().comments(product_id, filter, page, limit);
        comments.enqueue(callback);
    }

    public static void addComment(String order_id, String item_id, String content, String
            score, String images) {
        Observable<AddComment> addComment = ApiClient.getInstance().getApiService().addComments(order_id, item_id, content, score, images);
        addComment.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<AddComment>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(AddComment bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void addComment(String order_id, String item_id, String content, String score) {
        Observable<String> addComment = ApiClient.getInstance().getApiService().addComments(order_id, item_id, content, score);
        addComment.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String str) {
                                JSONObject jsonObject = null;
                                try {
                                    jsonObject = new JSONObject(str);
                                    if (jsonObject.has("code")) {
                                        int code = jsonObject.getInt("code");
                                        if (200 == code) {
                                            AddComment bean = gson.fromJson(str, AddComment.class);
                                            EventBus.getDefault().post(bean);
                                        } else {
                                            if (jsonObject.has("msg")) {
                                                String msg = jsonObject.getString("msg");
                                                ToastUtil.show(msg);
                                            } else {
                                                ToastUtil.show("数据异常，请稍后重试");
                                            }
                                        }
                                    }

                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                            }
                        }
                );
    }


    public static void deleteOrder(int id) {
        Observable<OrderDeleteBean> deleteOrder = ApiClient.getInstance().getApiService().deleteOrder(id);
        deleteOrder.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<String>() {
//                    @Override
//                    public void call(String str) {
//                        EventBus.getDefault().post(str);
//                    }
//                }
                        new Subscriber<OrderDeleteBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(OrderDeleteBean bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }


    public static void receiveOrder(int id) {
        Observable<ReceiveGoods> cancleOrder = ApiClient.getInstance().getApiService().receiveOrder(id);
        cancleOrder.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<ReceiveGoods>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(ReceiveGoods bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void orderDetail(int id) {
        Observable<OrderDetailBean> cancleOrder = ApiClient.getInstance().getApiService().orderDetail(id);
        cancleOrder.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<OrderDetailBean>() {
//                    @Override
//                    public void call(OrderDetailBean bean) {
//                        EventBus.getDefault().post(bean);
//                    }
//                }
                        new Subscriber<OrderDetailBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                Log.e(TAG, "onError: " + e.getMessage());

                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(OrderDetailBean orderDetailBean) {
                                EventBus.getDefault().post(orderDetailBean);
                            }
                        }
                );
    }


    public static void cancleOrder(int id, String reason) {
        Observable<String> cancleOrder = ApiClient.getInstance().getApiService().cancleOrder(id, reason);
        cancleOrder.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
//                        new Action1<String>() {
//                    @Override
//                    public void call(String str) {
//                        EventBus.getDefault().post(str);
//                    }
//                }
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String s) {
                                CancleOrderBean cancleOrderBean = gson.fromJson(s, CancleOrderBean.class);
                                if (null != cancleOrderBean) {
                                    EventBus.getDefault().post(cancleOrderBean);
                                }

                            }
                        }
                );
    }

    public static void picConfig() {
        Observable<PicBean> picConfig = ApiClient.getInstance().getApiService().picConfig();
        picConfig.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<PicBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(PicBean bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void updateMineInfo(String avatar, String username, String summary, String
            sex) {
        Observable<UpdateMineInfo> picConfig = ApiClient.getInstance().getApiService().updateMyInfo(avatar, username, summary, sex);
        picConfig.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<UpdateMineInfo>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(UpdateMineInfo bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void updateMineInfoAvatar(String avatar) {
        Observable<UpdateMineInfo> picConfig = ApiClient.getInstance().getApiService().updateMyInfoAvatar(avatar);
        picConfig.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<UpdateMineInfo>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(UpdateMineInfo bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void updateMineInfoUsername(String username) {
        Observable<UpdateMineInfo> picConfig = ApiClient.getInstance().getApiService().updateMyInfoUsername(username);
        picConfig.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<UpdateMineInfo>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(UpdateMineInfo bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void saveFav(int product_id) {
        Observable<String> saveFav = ApiClient.getInstance().getApiService().saveFav(product_id);
        saveFav.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String str) {
                                EventBus.getDefault().post(str);
                            }
                        }
                );
    }


    public static void delFav(int product_id) {
        Observable<String> saveFav = ApiClient.getInstance().getApiService().delFav(product_id);
        saveFav.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<String>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(String str) {
                                EventBus.getDefault().post(str);
                            }
                        }
                );
    }

    public static void updateMineInfoSummary(String summary) {
        Observable<UpdateMineInfo> picConfig = ApiClient.getInstance().getApiService().updateMyInfoSummary(summary);
        picConfig.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<UpdateMineInfo>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(UpdateMineInfo bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void updateMineInfoSex(String sex) {
        Observable<UpdateMineInfo> picConfig = ApiClient.getInstance().getApiService().updateMyInfoSex(sex);
        picConfig.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<UpdateMineInfo>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(UpdateMineInfo bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void updateMineInfo(String username, String summary, String sex) {
        Observable<UpdateMineInfo> picConfig = ApiClient.getInstance().getApiService().updateMyInfo(username, summary, sex);
        picConfig.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<UpdateMineInfo>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(UpdateMineInfo bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void meDetail() {
        Observable<MeDetailBean> picConfig = ApiClient.getInstance().getApiService().meDetail();
        picConfig.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<MeDetailBean>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(MeDetailBean bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }

    public static void offline() {
        Observable<Offline> offline = ApiClient.getInstance().getApiService().offline();
        offline.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Subscriber<Offline>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {
                                ToastUtil.show("网络异常，请稍后重试");
                            }

                            @Override
                            public void onNext(Offline bean) {
                                EventBus.getDefault().post(bean);
                            }
                        }
                );
    }


}